package com.sskj.bibi.presenter;

import com.lzy.okgo.model.Response;
import com.lzy.okrx2.adapter.FlowableBody;
import com.sskj.bibi.bean.CoinTypeBean;
import com.sskj.bibi.bean.EntrustBean;
import com.sskj.bibi.http.HttpConfig;
import com.sskj.bibi.ui.activity.HistoryEntrustActivity;
import com.sskj.common.base.HttpData;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.lib.http.JsonConverter;

import java.util.List;

import io.reactivex.Flowable;


public class HistoryEntrustActivityPresenter extends BasePresenter<HistoryEntrustActivity> {

    public Flowable<List<EntrustBean>> getEntrustHistoryFlow(String code, String type, String status, int page,String qu) {


        return httpService.getBibiTradeRecord(code, type, status, page,qu)
                .converter(new JsonConverter<HttpData<PageBean<EntrustBean>>>() {
                })
                .adapt(new FlowableBody<>())
                .map(pageBeanHttpData -> pageBeanHttpData.getData().getList());
    }

    public void getAllCoin(String  qu) {

        httpService.getAllCoinInfo(qu)
                .execute(new JsonCallBack<HttpData<List<CoinTypeBean>>>() {
                    @Override
                    public void onSuccess(Response<HttpData<List<CoinTypeBean>>> response) {
                        HttpData<List<CoinTypeBean>> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.updateCoinType(httpData.getData());
                        }
                    }
                });
    }

}
